package com.itheima.canal.listener;



import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

//广告监听类
@Component
public class AdListener {

    @Autowired
    private RestTemplate restTemplate;


    //从mq中取消息,指定队列
    @RabbitListener(queuesToDeclare=@Queue("ad_update_queue"))
    public void getAdMessage(String message) {
        System.out.println("接收到的广告消息是:" + message);
        //定义请求路径
        String url = "http://192.168.200.128/ad_update?position="+message;
    
        //发送http请求
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
        //解析响应数据
        if(forEntity.getStatusCode().value()==200){
            System.out.println("请求成功："+forEntity.getBody());
        }
    
    }

}
